package xyz.yuanjilu.service.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.job.flow.FlowJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import xyz.yuanjilu.entity.JobEntity;
import xyz.yuanjilu.service.BatchService;

@Service
public class BatchServiceImpl implements BatchService{
	@Autowired
	private Map<String, Job> jobMap;
	@Autowired
	private List<Job> jobs;
	
	
	@Override
	public JobEntity queryJob(String id) {
		// TODO Auto-generated method stub
		Job job = jobMap.get(id);
		return null;
	}

	@Override
	public List<JobEntity> queryJobs(Map<String, Object> map) {
		 List<JobEntity> jobEntitys=new ArrayList<JobEntity>();
	        for(Entry<String, Job> entry: jobMap.entrySet()) { 
	        	Job job = entry.getValue();
	            String id = entry.getKey();
	            JobEntity jobEntity=new JobEntity();
	            jobEntity.setId(id);
	            if (job instanceof FlowJob) {
					FlowJob flowJob = (FlowJob) job;
					Collection<String> stepNames = flowJob.getStepNames();
					jobEntity.setJobDescription(stepNames.toString());
					
				}
	            jobEntity.setJobName(job.getName());
				jobEntitys.add(jobEntity);
	        }
		return jobEntitys;
	}

	@Override
	public int queryJobsTotal(Map<String, Object> map) {
		return jobs.size();
	}
	
}
